package com.huihong.internship.system.Service.ServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huihong.internship.system.DTO.StudentPageQueryDTO;
import com.huihong.internship.system.DTO.TeacherScoreDTO;
import com.huihong.internship.system.Mapper.TeacherMapper;
import com.huihong.internship.system.Service.TeacherService;
import com.huihong.internship.system.VO.StudentDetailVO;
import com.huihong.internship.system.VO.StudentVO;
import com.huihong.internship.system.VO.InternshipMaterialItemVO;
import com.huihong.internship.system.entity.SysStudent;
import com.huihong.internship.system.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {


    @Autowired
    public TeacherMapper teacherMapper;


    /**
     * 分页查询指导学生列表
     * @param userId
     * @param dto
     * @return
     */
    @Override
    public PageResult getStudentPage(Long userId, StudentPageQueryDTO dto) {
        Integer pageNum = dto.getPageNum() == null || dto.getPageNum() <= 0 ? 1 : dto.getPageNum();
        Integer pageSize = dto.getPageSize() == null || dto.getPageSize() <= 0 ? 10 : dto.getPageSize();

        PageHelper.startPage(pageNum, pageSize);

        Page<StudentVO> page = teacherMapper.getStuPage(userId, dto);

        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 查看学生实习详情
     * @param studentId 学生ID
     * @return
     */
    @Override
    public StudentDetailVO getStudentDetail(Long studentId) {
        return teacherMapper.getStudentDetail(studentId);
    }


    /**
     * 查看学生提交的材料
     * @param studentId 学生ID
     * @param materialType 材料类型（可选：1 - 周志，2 - 实习报告，3 - 最终成果）
     * @return
     */
    @Override
    public List<InternshipMaterialItemVO> getStudentMaterials(Long studentId, Integer materialType) {
        return teacherMapper.getStudentMaterials(studentId, materialType);
    }


    /**
     * 给出材料反馈
     * @param materialId
     * @param teacherFeedback
     */
    @Override
    public void updateFeedback(Long materialId,String teacherFeedback) {
        teacherMapper.updateFeedback(materialId,teacherFeedback);

    }

    /**
     * 提交学生成绩评定
     * @param studentId 学生ID
     * @param scoreDTO 成绩评定数据
     */
    @Override
    public void submitScore(Long studentId, TeacherScoreDTO scoreDTO) {
        teacherMapper.submitScore(studentId, scoreDTO);
    }
}
